<h1>New media for an artwork</h1>
<% # TODO: split this file somehow into artist-only and artwork-only %>

<%= error_messages_for :media %>

<% form_for(@media, :url => admin_artwork_media_path(@artwork, @media), :html => { :multipart => true }) do |f| %>
<p>
<b><%= Artist.l_name.capitalize %></b><br />
<% if params[:artist_id] %>
	<%= @artist.name %>
	<%= f.hidden_field :artist_id, {:value => params[:artist_id]} %>
<% elsif params[:artwork_id] %>
	<%= @artist.fullname %>
	<%= f.hidden_field :artist_id, {:value => @artist.id} %>
<% else 
	if params[:select_artist] %>
		<%= select(:media, :artist_id, Artist.find(:all).collect {|a| [a.fullname, a.id]}, {:selected => params[:select_artist].to_i}) %>	
	<% else %>
		<%= collection_select(:media, :artist_id, Artist.find(:all), :id, :fullname, {:prompt => Media.l_attr('select artist')}) %>
	<% end %>
	<%= observe_field :media_artist_id, :url => {:action => :find_artworks}, :update => :media_artwork_id, :with => :artist %>
<% end %>
</p>

<% unless params[:artist_id] %>
  <p>
    <b><%= Artwork.l_name.capitalize %></b><br />
	 <% if params[:artwork_id] %>
	 <%= Artwork.find(params[:artwork_id]).name %>
	 <%= f.hidden_field :artwork_id, {:value => params[:artwork_id]} %>
	 <% elsif params[:select_artist] %>
	 <em><%= Media.l_attr('artist media explanation') %></em><br />
	 <%= select(:media, :artwork_id, Artwork.find_all_by_artist_id(params[:select_artist]).collect {|a| [a.name, a.id]}, {:include_blank => true, :selected => params[:select_artwork].to_i}) %>
	 <% else %>
	 <em><%= Media.l_attr('artist media explanation') %></em><br />
     <%= select(:media, :artwork_id, [[Media.l_attr('select artist'), '']]) %>
	 <% end %>
  </p>
<% end %>

  <p>
    <b><%= Media.l_attr('file') %></b><br />
    <%= file_column_field "media", :file %>
  </p>

  <p>
    <b><%= Media.l_attr('media type') %></b><br />
    <%= select(:media, :media_type, Media::OPTIONS) %>
  </p>

  <p>
    <b><%= Media.l_attr('caption') %></b><br />
    <%= f.text_field :caption %>
  </p>
	<%= hidden_field_tag :another, '0' %>
  <p>
    <%= f.submit l(:common, 'create') %>
  </p>
<% end %> <br />
